﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LeakView.service;
using LeakView.common;

namespace LeakView.misc.view
{
    public partial class MiscValueGrid : UserControl
    {

        private DataTable dataTable = new DataTable();

        public DataTable Table { get => dataTable; }


        public MiscValueGrid()
        {
            InitializeComponent();
        }

        public void addValues(List<AjaxMiscValue> values)
        {
            values.ForEach(v =>
            {
                this.addValue(v);
            });

        }

        public void addValue(AjaxMiscValue value)
        {
            addValue(value.birth, value.value);
        }

        public void addValue(long timestamp, double value)
        {
            DateTime dt = Tools.ConvertLongToDateTime(timestamp);

            int index = this.dataGridView1.Rows.Add();

            this.dataGridView1.Rows[index].Cells[0].Value = dt.ToString("yyyy-MM-dd HH:mm:ss");

            if (double.IsNaN(value))
                this.dataGridView1.Rows[index].Cells[1].Value = "";
            else
                this.dataGridView1.Rows[index].Cells[1].Value = value.ToString("F3");

        }

        public void clear()
        {
            this.dataGridView1.Rows.Clear();
        }
    }


}
